package com.sakura.common;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLIntegrityConstraintViolationException;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(SQLIntegrityConstraintViolationException.class)
    public R<Object> ExceptionHandler(SQLIntegrityConstraintViolationException e){
        String message = e.getMessage();
        String username = message.split(" ")[2];
        return R.error(username + "已有，请重复添加");
    }

    @ExceptionHandler(CustomerException.class)
    public R<Object> ExceptionHandler(CustomerException customerException){
        String message = customerException.getMessage();
        return R.error(message);
    }
}
